import {
	defineStore
} from 'pinia'
import {
	useMemoStore
} from '@/stores/memoStore'
export const filterMemoList = defineStore('filterMemoList', {
	state: () => ({
		filterDate: null
	}),

	getters: {
		memoList() {
			const memoStore = useMemoStore()
			return memoStore.memoList
		},

		filteredMemoList(state) {
			if (!state.filterDate) return this.memoList

			const filtered = []
			const filterDateStr = state.filterDate.toISOString().split('T')[0]

			this.memoList.forEach(item => {
				const endTime = item[2]
				const memoDateStr = endTime.split(' ')[0]				
				if(memoDateStr === filterDateStr) {
					filtered.push(item)
				}
			})

			return filtered
		}
	},

	actions: {
		setFilterDate(date) {
			this.filterDate = typeof date === 'string' ? new Date(date) : date;
		}
	}
})